package com.changeover.gwt.client.view.impl;

import com.changeover.gwt.client.view.ITaskView;
import com.changeover.gwt.client.view.task.impl.CustomerGridView;
import com.changeover.gwt.shared.datasource.impl.ComplexCustomerDataSource;
import com.changeover.gwt.shared.datasource.impl.StandardCustomerDataSource;
import com.changeover.gwt.shared.model.customer.ICustomer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class TaskView extends Composite implements ITaskView {

    private DialogBox customerDetaildWindow;
    private CustomerDetailsView customerDetailsPanel;
    
    @Override
    public DialogBox getCustomerDetailWidow() {
        return customerDetaildWindow;
    }
    
    public void showDetails(ICustomer customer) {
        customerDetailsPanel.setCustomer(customer);
        getCustomerDetailWidow().show();
    }
    
    public TaskView() {
        VerticalPanel mainPanel = new VerticalPanel();
        mainPanel.setSize("100%", "100%");
        
        customerDetaildWindow = new DialogBox();
        customerDetaildWindow.setModal(true);
        customerDetaildWindow.setText("Customer and account detail");
        
        customerDetailsPanel = new CustomerDetailsView();
        customerDetaildWindow.add(customerDetailsPanel);

        // complex panel
        VerticalPanel complexPanel = new VerticalPanel();
        complexPanel.setBorderWidth(1);
        mainPanel.add(complexPanel);
        complexPanel.setSize("100%", "100%");

        // complex label
        Label complexPanelTitle = new Label("Complex Group and Authorization");
        complexPanelTitle.setHeight("30px");
        complexPanelTitle.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        complexPanel.add(complexPanelTitle);
        complexPanel.setCellHeight(complexPanelTitle, "30px");
        
        // complex grid
        CustomerGridView complexCustomerGridView = new CustomerGridView(new ComplexCustomerDataSource());
        complexPanel.setCellHeight(complexCustomerGridView, "350px");
        complexPanel.add(complexCustomerGridView);
        complexCustomerGridView.setSize("100%", "100%");

        // standard panel
        VerticalPanel standardsPanel = new VerticalPanel();
        standardsPanel.setBorderWidth(1);
        mainPanel.add(standardsPanel);
        standardsPanel.setSize("100%", "100%");

        // standard label
        Label standardPanelTitle = new Label("Standard Customers");
        standardPanelTitle.setHeight("30px");
        standardPanelTitle.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        standardsPanel.add(standardPanelTitle);
        standardsPanel.setCellHeight(standardPanelTitle, "30px");
        
        // standard gid
        CustomerGridView standardCustomerGridView = new CustomerGridView(new StandardCustomerDataSource());
        standardsPanel.setCellHeight(standardCustomerGridView, "350px");
        standardsPanel.add(standardCustomerGridView);
        standardCustomerGridView.setSize("100%", "100%");

        initWidget(mainPanel);
    }

}
